Skip to content

[win] Don't build a custom nanosleep() when not needed#1256

Open
dimula73 wants to merge 3 commits into
mltframework:masterfrom
dimula73:kazakov/win-fix-build-llvm-mingw
Open

[win] Don't build a custom nanosleep() when not needed#1256
dimula73 wants to merge 3 commits into
mltframework:masterfrom
dimula73:kazakov/win-fix-build-llvm-mingw

Conversation

@dimula73

Copy link
Copy Markdown
Contributor

Instead of relying of the includes order we should properly
check if the function is actually provided by our version
of pthread library.

The patch basically reverts an original hack to resolve the
issue in msys2 and implements a proper detection mechanism
for the presence of nanosleep() in the pthread library

dimula73 added 2 commits June 10, 2026 17:29
Instead of relying of the includes order we should properly
check if the function is actually provided by our version
of pthread library.
@dimula73

dimula73 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

There is still an unorthodox usage of WIN_PTHREADS_TIME_H in mlt_types.h, which dates back from 2015. Theoretically, it could also be replaced with HAVE_PTHREAD_NANOSLEEP, though we would then have to add a public-interface definition for libmlt, like that:

target_compile_definitions(mlt PUBLIC "HAVE_PTHREAD_NANOSLEEP=${HAVE_PTHREAD_NANOSLEEP}")

Though I'm not sure if such a change is acceptable or not

It seems like there is some issue with that with MSYS2:

msys2/MINGW-packages#10459
@ddennedy

Copy link
Copy Markdown
Member

unorthodox usage of WIN_PTHREADS_TIME_H in mlt_types.h

It used to exist even if not in a standard. Google search on it first hit leads me to;
https://github.com/tonytheodore/winpthreads/blob/master/include/pthread_time.h

Since it is unorthodox it is OK to change it IMO.

@ddennedy

Copy link
Copy Markdown
Member

I approve the change but wait to see what you do about mlt_types.h

@dimula73

dimula73 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Hi, @ddennedy!

I did a small test here and it seems like it is not easy to add HAVE_PTHREAD_NANOSLEEP into a global definitions interface of the entire library (.pc and Mlt7Config.cmake files will have to be adjusted for that manually).

So, we have three options here:

  1. Merge this patch as it is and ignore the fact that the implementation and prototype for MLT's nanosleep() are guarded by different definitions.

  2. Revert nanosleep()'s implementation to be guarded by the undocumented WIN_PTHREADS_TIME_H and just include pthread_time.h into the translation unit as well (this version will be the nearest to the original implementation)

  3. Add a global mlt_config.h file, which would be generated by CMake and provide this macro for mlt_types.h.

@ddennedy

Copy link
Copy Markdown
Member

nanosleep() for win32 is only supposed to be used internally but was added to mlt_types.h for convenience. We can add a src/win32/mlt_win32.h, but then it needs to be conditionally included wherever nanosleep is called. Or, your option 2 if __MINGW32__

Comment thread src/framework/mlt_types.h
Comment on lines 5 to +28
@@ -22,6 +22,10 @@
#ifndef MLT_TYPES_H
#define MLT_TYPES_H

#ifndef GCC_VERSION
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has too many unnecessary changes:

  • reverting a copyright year
  • adding this GCC_VERSION macro that is not used

Comment thread src/win32/win32.c
Comment on lines +50 to +58
int nanosleep( const struct timespec * rqtp, struct timespec * rmtp )
{
if (rqtp->tv_nsec > 999999999) {
/* The time interval specified 1,000,000 or more microseconds. */
errno = EINVAL;
return -1;
}
return usleep(rqtp->tv_sec * 1000000 + rqtp->tv_nsec / 1000);
}
return usleep( rqtp->tv_sec * 1000000 + rqtp->tv_nsec / 1000 );
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not change white space: spaces to tabs, and extra spaces added inside parantheses

Comment thread CMakeLists.txt
Comment on lines -210 to -211
if(MINGW)
string(REPLACE "iconv" "pthread" MLT_PTHREAD_LIBS "${Iconv_LIBRARY}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added for a reason not too long ago. See git blame. Explain why it is no longer needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants